/****************************************************************
* Copyright (c) 2006-2021 Jingjia Micro Co., Ltd.
*
* File    :   table.h
* Author  :   luomin1249
* Date    :   2021/08/03
* Desc    :
* Other   :
*              
* History:
* Date        Modifier       Content 
*****************************************************************/

#ifndef __TABLE_H__
#define __TABLE_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "gp_timer.h"
#include "list.h"
#include "common.h"

typedef void *(*hook_t)(void *);

typedef struct table_entry
{
    list_t knot;
    void *data; 
} table_entry_t;

/**
 * Base structure of table
 */
typedef struct table
{ 
    table_entry_t *table_header;
    gp_timer_t *table_timer; 
    hook_t table_hook;
    int8_t name[64];
} table_t;


table_t *table_create(char *name);
int32_t table_init(table_t *table, gp_timer_t *timer, hook_t hook);
int32_t table_delete(table_t *table);
void table_insert_before(table_t *table, table_entry_t *entry);
void table_insert_after(table_t *table, table_entry_t *entry);
void table_remove_entry(table_entry_t *entry);
bool table_isempty(table_t *table);
int32_t table_len(table_t *table);
table_entry_t *create_table_entry(void *data);
void table_attach_hook(table_t *table, hook_t hook);
int32_t table_delete_entry(table_t *table);

#define table_for_each_entry(pos, h, knot) list_for_each_entry(pos, h, knot)

#ifdef __cplusplus
}
#endif

#endif